﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;

namespace Orchard.WebApi
{
    public class DefaultOrchardHttpControllerTypeResolver : DefaultHttpControllerTypeResolver, IHttpControllerTypeResolver
    {
        public override ICollection<Type> GetControllerTypes(IAssembliesResolver assembliesResolver)
        {
            List<Type> types = new List<Type>();
            var assemblys = assembliesResolver.GetAssemblies();
            foreach (var assembly in assemblys)
            {
                types.AddRange(assembly.GetTypes().Where(x => typeof(IHttpController).IsAssignableFrom(x)));
            }
            return types;
        }
    }
}
